﻿Imports DTO
Imports System.Data.SqlClient

Public Class QuyenDAO
    Public Function LayDSQuyen(ByVal _taiKhoan As TaiKhoanDTO) As List(Of QuyenDTO)
        Dim sql As String = "Select * from Quyen where MaLoaiTK = " & _taiKhoan.LoaiTK

        Dim _listQuyen As New List(Of QuyenDTO)

        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)

        For Each row As DataRow In dt.Rows
            Dim _maLoaiTK As Integer = Integer.Parse(row("MaLoaiTK").ToString())
            Dim _maCTQuyen As Integer = Integer.Parse(row("MaCTQuyen").ToString())
            Dim _quyen As New QuyenDTO(_maLoaiTK, _maCTQuyen)
            _listQuyen.Add(_quyen)
        Next

        Return _listQuyen

    End Function

    Public Sub SetQuyenDAO(ByVal _tenQuyen As String, ByVal _maLoaiTK As Integer, ByVal _thaoTac As Integer)

        Dim sql As String = "sp_SetQuyen"
        Dim _listPara As New List(Of SqlParameter)

        Dim Quyen As New SqlParameter("@Quyen", SqlDbType.VarChar)
        Quyen.Value = _tenQuyen
        _listPara.Add(Quyen)

        Dim MaLoaiTK As New SqlParameter("@MaLoaiTK", SqlDbType.Int)
        MaLoaiTK.Value = _maLoaiTK
        _listPara.Add(MaLoaiTK)

        Dim ThaoTac As New SqlParameter("@ThaoTac", SqlDbType.Int)
        ThaoTac.Value = _thaoTac
        _listPara.Add(ThaoTac)

        DataProvider.ExcuteQueryProc(sql, _listPara)
    End Sub
End Class
